{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Understanding NumPy Array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 2  4  6  8 10]\n"
     ]
    }
   ],
   "source": [
    "# Creating an array\n",
    "import numpy as np\n",
    "a = np.array([2,4,6,8,10])\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1  2  3  4  5  6  7  8  9 10]\n"
     ]
    }
   ],
   "source": [
    "# Creating an array using arange()\n",
    "import numpy as np\n",
    "a = np.arange(1,11)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0. 0. 0.]\n",
      " [0. 0. 0.]\n",
      " [0. 0. 0.]]\n",
      "[[1. 1.]\n",
      " [1. 1.]]\n",
      "[[4 4]\n",
      " [4 4]]\n",
      "[[1. 0. 0. 0.]\n",
      " [0. 1. 0. 0.]\n",
      " [0. 0. 1. 0.]\n",
      " [0. 0. 0. 1.]]\n",
      "[[0.59054856 0.78109647 0.66402512]\n",
      " [0.86504473 0.45696972 0.02128842]\n",
      " [0.79086473 0.14487524 0.71841093]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "p = np.zeros((3,3))   # Create an array of all zeros\n",
    "print(p) \n",
    "\n",
    "q = np.ones((2,2))    # Create an array of all ones\n",
    "print(q)\n",
    "\n",
    "r = np.full((2,2), 4)  # Create a constant array\n",
    "print(r) \n",
    "\n",
    "s = np.eye(4)         # Create a 2x2 identity matrix\n",
    "print(s) \n",
    "\n",
    "t = np.random.random((3,3))  # Create an array filled with random values\n",
    "print(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n",
      "int64\n"
     ]
    }
   ],
   "source": [
    "# Creating an array using arange()\n",
    "import numpy as np\n",
    "a = np.arange(1,11)\n",
    "print(type(a))\n",
    "print(a.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(10,)\n"
     ]
    }
   ],
   "source": [
    "# check shape pf Array\n",
    "print(a.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[5 6]\n",
      " [7 8]]\n"
     ]
    }
   ],
   "source": [
    "a = np.array([[5,6],[7,8]])\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "source": [
    "print(a[0,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "print(a[0,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n"
     ]
    }
   ],
   "source": [
    "print(a[1,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n"
     ]
    }
   ],
   "source": [
    "print(a[1,1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## NumPy Array Numerical Data Types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21.0\n"
     ]
    }
   ],
   "source": [
    "print(np.float64(21))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21\n"
     ]
    }
   ],
   "source": [
    "print(np.int8(21.0)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(np.bool(21))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "print(np.bool(0)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(np.bool(21.0)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.0\n"
     ]
    }
   ],
   "source": [
    "print(np.float(True)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.0\n"
     ]
    }
   ],
   "source": [
    "print(np.float(False)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1.  2.  3.  4.  5.  6.  7.  8.  9. 10.]\n"
     ]
    }
   ],
   "source": [
    "arr=np.arange(1,11, dtype= np.float32)\n",
    "\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can't convert complex to int",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-19-61a3a50e24b1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m42.0\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1.j\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: can't convert complex to int"
     ]
    }
   ],
   "source": [
    "np.int(42.0 + 1.j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(42+1j)\n"
     ]
    }
   ],
   "source": [
    "c= complex(42, 1)\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "42.0 1.0\n"
     ]
    }
   ],
   "source": [
    "print(c.real,c.imag)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "int64\n"
     ]
    }
   ],
   "source": [
    "# Creating an array\n",
    "import numpy as np\n",
    "a = np.array([2,4,6,8,10])\n",
    "\n",
    "print(a.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n"
     ]
    }
   ],
   "source": [
    "print(a.dtype.itemsize)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1.  2.  3.  4.  5.  6.  7.  8.  9. 10.]\n"
     ]
    }
   ],
   "source": [
    "# Create numpy array using arange() function\n",
    "var1=np.arange(1,11, dtype='f')\n",
    "\n",
    "print(var1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1.+0.j 2.+0.j 3.+0.j 4.+0.j 5.+0.j]\n"
     ]
    }
   ],
   "source": [
    "print(np.arange(1,6, dtype='D'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "float64\n"
     ]
    }
   ],
   "source": [
    "print(np.dtype(float))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "float32\n"
     ]
    }
   ],
   "source": [
    "print(np.dtype('f'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "float64\n"
     ]
    }
   ],
   "source": [
    "print(np.dtype('d')) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "float64\n"
     ]
    }
   ],
   "source": [
    "print(np.dtype('f8'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d\n"
     ]
    }
   ],
   "source": [
    "var2=np.array([1,2,3],dtype='float64')\n",
    "\n",
    "print(var2.dtype.char)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.float64'>\n"
     ]
    }
   ],
   "source": [
    "print(var2.dtype.type)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Manipulating Shape of NumPy Array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create an array\n",
    "arr = np.arange(12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2]\n",
      " [ 3  4  5]\n",
      " [ 6  7  8]\n",
      " [ 9 10 11]]\n"
     ]
    }
   ],
   "source": [
    "# Reshape the array dimension\n",
    "new_arr=arr.reshape(4,3)\n",
    "\n",
    "print(new_arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]]\n"
     ]
    }
   ],
   "source": [
    "# Reshape the array dimension\n",
    "new_arr2=arr.reshape(3,4)\n",
    "\n",
    "print(new_arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]\n",
      " [7 8 9]]\n"
     ]
    }
   ],
   "source": [
    "# Create an array\n",
    "arr=np.arange(1,10).reshape(3,3)\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5 6 7 8 9]\n"
     ]
    }
   ],
   "source": [
    "# flatten the array\n",
    "print(arr.flatten())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5 6 7 8 9]\n"
     ]
    }
   ],
   "source": [
    "# ravel() function \n",
    "print(arr.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 4 7]\n",
      " [2 5 8]\n",
      " [3 6 9]]\n"
     ]
    }
   ],
   "source": [
    "# Transpose the matrix\n",
    "print(arr.transpose())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3 4 5 6 7 8 9]]\n"
     ]
    }
   ],
   "source": [
    "# resize the matrix\n",
    "arr.resize(1,9)\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Stacking of Numpy arrays"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]\n",
      " [7 8 9]]\n"
     ]
    }
   ],
   "source": [
    "arr1 = np.arange(1,10).reshape(3,3)\n",
    "print(arr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 2  4  6]\n",
      " [ 8 10 12]\n",
      " [14 16 18]]\n"
     ]
    }
   ],
   "source": [
    "arr2 = 2*arr1\n",
    "print(arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2  3  2  4  6]\n",
      " [ 4  5  6  8 10 12]\n",
      " [ 7  8  9 14 16 18]]\n"
     ]
    }
   ],
   "source": [
    "arr3=np.hstack((arr1, arr2))\n",
    "\n",
    "print(arr3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2  3  2  4  6]\n",
      " [ 4  5  6  8 10 12]\n",
      " [ 7  8  9 14 16 18]]\n"
     ]
    }
   ],
   "source": [
    "# Horizontal stacking using concatenate() function\n",
    "arr4=np.concatenate((arr1, arr2), axis=1)\n",
    "print(arr4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2  3]\n",
      " [ 4  5  6]\n",
      " [ 7  8  9]\n",
      " [ 2  4  6]\n",
      " [ 8 10 12]\n",
      " [14 16 18]]\n"
     ]
    }
   ],
   "source": [
    "arr5=np.vstack((arr1, arr2))\n",
    "print(arr5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2  3]\n",
      " [ 4  5  6]\n",
      " [ 7  8  9]\n",
      " [ 2  4  6]\n",
      " [ 8 10 12]\n",
      " [14 16 18]]\n"
     ]
    }
   ],
   "source": [
    "arr6=np.concatenate((arr1, arr2), axis=0) \n",
    "print(arr6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[ 1  2]\n",
      "  [ 2  4]\n",
      "  [ 3  6]]\n",
      "\n",
      " [[ 4  8]\n",
      "  [ 5 10]\n",
      "  [ 6 12]]\n",
      "\n",
      " [[ 7 14]\n",
      "  [ 8 16]\n",
      "  [ 9 18]]]\n"
     ]
    }
   ],
   "source": [
    "arr7=np.dstack((arr1, arr2))\n",
    "print(arr7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4 5 6]\n"
     ]
    }
   ],
   "source": [
    "# Create 1-D array\n",
    "arr1 = np.arange(4,7) \n",
    "print(arr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 8 10 12]\n"
     ]
    }
   ],
   "source": [
    "# Create 1-D array\n",
    "arr2 = 2 * arr1\n",
    "print(arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 4  8]\n",
      " [ 5 10]\n",
      " [ 6 12]]\n"
     ]
    }
   ],
   "source": [
    "# Create column stack\n",
    "arr_col_stack = np.column_stack((arr1,arr2))\n",
    "print(arr_col_stack)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 4  5  6]\n",
      " [ 8 10 12]]\n"
     ]
    }
   ],
   "source": [
    "# Create row stack\n",
    "arr_row_stack = np.row_stack((arr1,arr2)) \n",
    "print(arr_row_stack)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Partitioning Numpy Array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]\n",
      " [7 8 9]]\n"
     ]
    }
   ],
   "source": [
    "# Create an array\n",
    "arr=np.arange(1,10).reshape(3,3)\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[array([[1],\n",
      "       [4],\n",
      "       [7]]), array([[2],\n",
      "       [5],\n",
      "       [8]]), array([[3],\n",
      "       [6],\n",
      "       [9]])]\n"
     ]
    }
   ],
   "source": [
    "# Peroform horizontal splitting\n",
    "arr_hor_split=np.hsplit(arr, 3)\n",
    "\n",
    "print(arr_hor_split)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[array([[1, 2, 3]]), array([[4, 5, 6]]), array([[7, 8, 9]])]\n"
     ]
    }
   ],
   "source": [
    "# vertical split\n",
    "arr_ver_split=np.vsplit(arr, 3)\n",
    "\n",
    "print(arr_ver_split)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[array([[1, 2, 3]]), array([[4, 5, 6]]), array([[7, 8, 9]])]\n"
     ]
    }
   ],
   "source": [
    "# split with axis=0\n",
    "arr_split=np.split(arr,3,axis=0)\n",
    "\n",
    "print(arr_split)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[1],\n",
       "        [4],\n",
       "        [7]]), array([[2],\n",
       "        [5],\n",
       "        [8]]), array([[3],\n",
       "        [6],\n",
       "        [9]])]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# split with axis=1\n",
    "np.split(arr,3,axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Changing Datatype of NumPy Arrays"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Integer Array: [[1 2 3]\n",
      " [4 5 6]\n",
      " [7 8 9]]\n",
      "Float Array: [[1. 2. 3.]\n",
      " [4. 5. 6.]\n",
      " [7. 8. 9.]]\n",
      "Changed Datatype: float64\n"
     ]
    }
   ],
   "source": [
    "# Create an array\n",
    "arr=np.arange(1,10).reshape(3,3)\n",
    "print(\"Integer Array:\",arr)\n",
    "\n",
    "# Change datatype of array\n",
    "arr=arr.astype(float)\n",
    "\n",
    "# print array\n",
    "print(\"Float Array:\", arr)\n",
    "\n",
    "# Check new data type of array\n",
    "print(\"Changed Datatype:\", arr.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "float64\n"
     ]
    }
   ],
   "source": [
    "# Change datatype of array\n",
    "arr=arr.astype(float)\n",
    "\n",
    "# Check new data type of array\n",
    "print(arr.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n"
     ]
    }
   ],
   "source": [
    "# Create an array\n",
    "arr=np.arange(1,10)\n",
    "\n",
    "# Convert NumPy array to Python List\n",
    "list1=arr.tolist()\n",
    "print(list1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Creating NumPy views and copies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [3 4]]\n",
      "Original Array:  140586368570352\n",
      "Assignment:  140586368570352\n",
      "Deep Copy:  140586368570752\n",
      "Shallow Copy(View):  140586368570832\n"
     ]
    }
   ],
   "source": [
    "# Create NumPy Array\n",
    "arr = np.arange(1,5).reshape(2,2)\n",
    "print(arr)\n",
    "\n",
    "# Create no copy only assignment\n",
    "arr_no_copy=arr\n",
    "\n",
    "# Create Deep Copy\n",
    "arr_copy=arr.copy()\n",
    "\n",
    "# Create shallow copy using View\n",
    "arr_view=arr.view()\n",
    "\n",
    "print(\"Original Array: \",id(arr))\n",
    "print(\"Assignment: \",id(arr_no_copy))\n",
    "print(\"Deep Copy: \",id(arr_copy))\n",
    "print(\"Shallow Copy(View): \",id(arr_view))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "View Array:\n",
      " [[ 1  2]\n",
      " [99 89]]\n",
      "Copied Array:\n",
      " [[1 2]\n",
      " [3 4]]\n"
     ]
    }
   ],
   "source": [
    "# Update the values of original array\n",
    "arr[1]=[99,89]\n",
    "\n",
    "# Check values of array view\n",
    "print(\"View Array:\\n\", arr_view)\n",
    "\n",
    "# Check values of array copy\n",
    "print(\"Copied Array:\\n\", arr_copy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Slicing NumPy Array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n"
     ]
    }
   ],
   "source": [
    "# Create NumPy Array\n",
    "arr = np.arange(10) \n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3 4 5]\n"
     ]
    }
   ],
   "source": [
    "print(arr[3:6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3 4 5 6 7 8 9]\n"
     ]
    }
   ],
   "source": [
    "print(arr[3:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[7 8 9]\n"
     ]
    }
   ],
   "source": [
    "print(arr[-3:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2 4 6]\n"
     ]
    }
   ],
   "source": [
    "print(arr[2:7:2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Boolean and Fancy Indexing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Orignial Array:\n",
      " [21 23 25 27 29 31 33 35 37 39]\n",
      "After Boolean Condition: [31 33 35 37 39]\n"
     ]
    }
   ],
   "source": [
    "# Create NumPy Array\n",
    "arr = np.arange(21,41,2)\n",
    "print(\"Orignial Array:\\n\",arr)\n",
    "\n",
    "# Boolean Indexing\n",
    "print(\"After Boolean Condition:\",arr[arr>30])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Orignial Array:\n",
      " [[ 1  2  3  4]\n",
      " [ 5  6  7  8]\n",
      " [ 9 10 11 12]\n",
      " [13 14 15 16]\n",
      " [17 18 19 20]]\n",
      "Selected 1st and 2nd Row:\n",
      " [[ 5  6  7  8]\n",
      " [ 9 10 11 12]]\n",
      "Selected 3rd and 4th Row:\n",
      " [[ 9 10 11 12]\n",
      " [13 14 15 16]]\n"
     ]
    }
   ],
   "source": [
    "# Create NumPy Array\n",
    "arr = np.arange(1,21).reshape(5,4)\n",
    "print(\"Orignial Array:\\n\",arr)\n",
    "\n",
    "# Selecting 2nd and 3rd row\n",
    "indices = [1,2]\n",
    "print(\"Selected 1st and 2nd Row:\\n\", arr[indices])\n",
    "\n",
    "# Selecting 3nd and 4th row\n",
    "indices = [2,3]\n",
    "print(\"Selected 3rd and 4th Row:\\n\", arr[indices])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Selected Sub-Array: [ 7 12]\n"
     ]
    }
   ],
   "source": [
    "# Create row and column indices\n",
    "row = np.array([1, 2])\n",
    "col = np.array([2, 3])\n",
    "\n",
    "print(\"Selected Sub-Array:\", arr[row, col])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Broadcasting arrays"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [3 4]]\n"
     ]
    }
   ],
   "source": [
    "# Create NumPy Array\n",
    "arr1 = np.arange(1,5).reshape(2,2) \n",
    "print(arr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[5 6]\n",
      " [7 8]]\n"
     ]
    }
   ],
   "source": [
    "# Create another NumPy Array\n",
    "arr2 = np.arange(5,9).reshape(2,2) \n",
    "print(arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 6  8]\n",
      " [10 12]]\n"
     ]
    }
   ],
   "source": [
    "# Add two matrices\n",
    "print(arr1+arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 5 12]\n",
      " [21 32]]\n"
     ]
    }
   ],
   "source": [
    "# Multiply two matrices\n",
    "print(arr1*arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[4 5]\n",
      " [6 7]]\n"
     ]
    }
   ],
   "source": [
    "# Add a scaler value\n",
    "print(arr1 + 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 3  6]\n",
      " [ 9 12]]\n"
     ]
    }
   ],
   "source": [
    "# Multiply with a scalar value\n",
    "print(arr1 * 3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Import pandas library \n",
    "import pandas as pd \n",
    "# Create empty DataFrame\n",
    "df = pd.DataFrame() \n",
    "\n",
    "# Header of dataframe. \n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Vijay</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Sundar</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Satyam</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Indira</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Name  Age\n",
       "0   Vijay   23\n",
       "1  Sundar   45\n",
       "2  Satyam   46\n",
       "3  Indira   52"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create dictionary of list\n",
    "data = {'Name': ['Vijay', 'Sundar', 'Satyam', 'Indira'], 'Age': [23, 45, 46, 52 ]}   \n",
    "\n",
    "# Create the pandas DataFrame \n",
    "df = pd.DataFrame(data)\n",
    "\n",
    "# Header of dataframe. \n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Vijay</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Sundar</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Shankar</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Name  Age\n",
       "0    Vijay   23\n",
       "1   Sundar   25\n",
       "2  Shankar   26"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Pandas DataFrame by lists of dicts. \n",
    "# Initialise data to lists. \n",
    "data =[ {'Name': 'Vijay',  'Age': 23},{'Name': 'Sundar',  'Age': 25},{'Name': 'Shankar',  'Age': 26}]\n",
    "# Creates DataFrame. \n",
    "df = pd.DataFrame(data,columns=['Name','Age']) \n",
    "# Print dataframe header \n",
    "df.head()  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Vijay</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Sundar</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Satyam</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Indira</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Name  Age\n",
       "0   Vijay   23\n",
       "1  Sundar   45\n",
       "2  Satyam   46\n",
       "3  Indira   52"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Creating DataFrame using list of tuples.\n",
    "data = [('Vijay', 23),( 'Sundar', 45), ('Satyam', 46), ('Indira',52)] \n",
    "# Create dataframe\n",
    "df = pd.DataFrame(data, columns=['Name','Age'])\n",
    "# Print dataframe header \n",
    "df.head()  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pandas Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     Ajay\n",
       "1      Jay\n",
       "2    Vijay\n",
       "dtype: object"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Creating Pandas Series using Dictionary\n",
    "dict1 = {0 : 'Ajay', 1 : 'Jay', 2 : 'Vijay'}\n",
    "# Create Pandas Series\n",
    "series = pd.Series(dict1)\n",
    "# Show series\n",
    "series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    51\n",
       "1    65\n",
       "2    48\n",
       "3    59\n",
       "4    68\n",
       "dtype: int64"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# load Pandas and NumPy\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "# Create NumPy array\n",
    "arr = np.array([51,65,48,59, 68])\n",
    "# Create Pandas Series\n",
    "series = pd.Series(arr)\n",
    "series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    10\n",
       "1    10\n",
       "2    10\n",
       "3    10\n",
       "4    10\n",
       "5    10\n",
       "dtype: int64"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# load Pandas and NumPy\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "# Create Pandas Series\n",
    "series = pd.Series(10, index=[0, 1, 2, 3, 4, 5])\n",
    "series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>CountryID</th>\n",
       "      <th>Continent</th>\n",
       "      <th>Adolescent fertility rate (%)</th>\n",
       "      <th>Adult literacy rate (%)</th>\n",
       "      <th>Gross national income per capita (PPP international $)</th>\n",
       "      <th>Net primary school enrolment ratio female (%)</th>\n",
       "      <th>Net primary school enrolment ratio male (%)</th>\n",
       "      <th>Population (in thousands) total</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>151.0</td>\n",
       "      <td>28.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26088.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Albania</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>27.0</td>\n",
       "      <td>98.7</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>93.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>3172.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Algeria</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>6.0</td>\n",
       "      <td>69.9</td>\n",
       "      <td>5940.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>96.0</td>\n",
       "      <td>33351.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Andorra</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>83.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>74.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Angola</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>146.0</td>\n",
       "      <td>67.4</td>\n",
       "      <td>3890.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>51.0</td>\n",
       "      <td>16557.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Country  CountryID  Continent  Adolescent fertility rate (%)  \\\n",
       "0  Afghanistan          1          1                          151.0   \n",
       "1      Albania          2          2                           27.0   \n",
       "2      Algeria          3          3                            6.0   \n",
       "3      Andorra          4          2                            NaN   \n",
       "4       Angola          5          3                          146.0   \n",
       "\n",
       "   Adult literacy rate (%)  \\\n",
       "0                     28.0   \n",
       "1                     98.7   \n",
       "2                     69.9   \n",
       "3                      NaN   \n",
       "4                     67.4   \n",
       "\n",
       "   Gross national income per capita (PPP international $)  \\\n",
       "0                                                NaN        \n",
       "1                                             6000.0        \n",
       "2                                             5940.0        \n",
       "3                                                NaN        \n",
       "4                                             3890.0        \n",
       "\n",
       "   Net primary school enrolment ratio female (%)  \\\n",
       "0                                            NaN   \n",
       "1                                           93.0   \n",
       "2                                           94.0   \n",
       "3                                           83.0   \n",
       "4                                           49.0   \n",
       "\n",
       "   Net primary school enrolment ratio male (%)  \\\n",
       "0                                          NaN   \n",
       "1                                         94.0   \n",
       "2                                         96.0   \n",
       "3                                         83.0   \n",
       "4                                         51.0   \n",
       "\n",
       "   Population (in thousands) total  \n",
       "0                          26088.0  \n",
       "1                           3172.0  \n",
       "2                          33351.0  \n",
       "3                             74.0  \n",
       "4                          16557.0  "
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Import pandas \n",
    "import pandas as pd\n",
    "\n",
    "# Load data using read_csv() \n",
    "df = pd.read_csv(\"WHO_first9cols.csv\")\n",
    "\n",
    "# Show initial 5 records\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>CountryID</th>\n",
       "      <th>Continent</th>\n",
       "      <th>Adolescent fertility rate (%)</th>\n",
       "      <th>Adult literacy rate (%)</th>\n",
       "      <th>Gross national income per capita (PPP international $)</th>\n",
       "      <th>Net primary school enrolment ratio female (%)</th>\n",
       "      <th>Net primary school enrolment ratio male (%)</th>\n",
       "      <th>Population (in thousands) total</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>197</th>\n",
       "      <td>Vietnam</td>\n",
       "      <td>198</td>\n",
       "      <td>6</td>\n",
       "      <td>25.0</td>\n",
       "      <td>90.3</td>\n",
       "      <td>2310.0</td>\n",
       "      <td>91.0</td>\n",
       "      <td>96.0</td>\n",
       "      <td>86206.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>198</th>\n",
       "      <td>West Bank and Gaza</td>\n",
       "      <td>199</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>199</th>\n",
       "      <td>Yemen</td>\n",
       "      <td>200</td>\n",
       "      <td>1</td>\n",
       "      <td>83.0</td>\n",
       "      <td>54.1</td>\n",
       "      <td>2090.0</td>\n",
       "      <td>65.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>21732.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>200</th>\n",
       "      <td>Zambia</td>\n",
       "      <td>201</td>\n",
       "      <td>3</td>\n",
       "      <td>161.0</td>\n",
       "      <td>68.0</td>\n",
       "      <td>1140.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>11696.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>201</th>\n",
       "      <td>Zimbabwe</td>\n",
       "      <td>202</td>\n",
       "      <td>3</td>\n",
       "      <td>101.0</td>\n",
       "      <td>89.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>88.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>13228.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Country  CountryID  Continent  Adolescent fertility rate (%)  \\\n",
       "197             Vietnam        198          6                           25.0   \n",
       "198  West Bank and Gaza        199          1                            NaN   \n",
       "199               Yemen        200          1                           83.0   \n",
       "200              Zambia        201          3                          161.0   \n",
       "201            Zimbabwe        202          3                          101.0   \n",
       "\n",
       "     Adult literacy rate (%)  \\\n",
       "197                     90.3   \n",
       "198                      NaN   \n",
       "199                     54.1   \n",
       "200                     68.0   \n",
       "201                     89.5   \n",
       "\n",
       "     Gross national income per capita (PPP international $)  \\\n",
       "197                                             2310.0        \n",
       "198                                                NaN        \n",
       "199                                             2090.0        \n",
       "200                                             1140.0        \n",
       "201                                                NaN        \n",
       "\n",
       "     Net primary school enrolment ratio female (%)  \\\n",
       "197                                           91.0   \n",
       "198                                            NaN   \n",
       "199                                           65.0   \n",
       "200                                           94.0   \n",
       "201                                           88.0   \n",
       "\n",
       "     Net primary school enrolment ratio male (%)  \\\n",
       "197                                         96.0   \n",
       "198                                          NaN   \n",
       "199                                         85.0   \n",
       "200                                         90.0   \n",
       "201                                         87.0   \n",
       "\n",
       "     Population (in thousands) total  \n",
       "197                          86206.0  \n",
       "198                              NaN  \n",
       "199                          21732.0  \n",
       "200                          11696.0  \n",
       "201                          13228.0  "
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Show last 5 records\n",
    "df.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Shape: (202, 9)\n"
     ]
    }
   ],
   "source": [
    "# Show the shape of DataFrame\n",
    "print(\"Shape:\", df.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "List of Columns: Index(['Country', 'CountryID', 'Continent', 'Adolescent fertility rate (%)',\n",
      "       'Adult literacy rate (%)',\n",
      "       'Gross national income per capita (PPP international $)',\n",
      "       'Net primary school enrolment ratio female (%)',\n",
      "       'Net primary school enrolment ratio male (%)',\n",
      "       'Population (in thousands) total'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "# Check the column list of DataFrame\n",
    "print(\"List of Columns:\", df.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data types: Country                                                    object\n",
      "CountryID                                                   int64\n",
      "Continent                                                   int64\n",
      "Adolescent fertility rate (%)                             float64\n",
      "Adult literacy rate (%)                                   float64\n",
      "Gross national income per capita (PPP international $)    float64\n",
      "Net primary school enrolment ratio female (%)             float64\n",
      "Net primary school enrolment ratio male (%)               float64\n",
      "Population (in thousands) total                           float64\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "# Show the datatypes of columns\n",
    "print(\"Data types:\", df.dtypes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Select a series\n",
    "country_series=df['Country']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# check datatype of series\n",
    "type(country_series)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RangeIndex(start=0, stop=202, step=1)\n"
     ]
    }
   ],
   "source": [
    "print(country_series.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Afghanistan' 'Albania' 'Algeria' 'Andorra' 'Angola'\n",
      " 'Antigua and Barbuda' 'Argentina' 'Armenia' 'Australia' 'Austria'\n",
      " 'Azerbaijan' 'Bahamas' 'Bahrain' 'Bangladesh' 'Barbados' 'Belarus'\n",
      " 'Belgium' 'Belize' 'Benin' 'Bermuda' 'Bhutan' 'Bolivia'\n",
      " 'Bosnia and Herzegovina' 'Botswana' 'Brazil' 'Brunei Darussalam'\n",
      " 'Bulgaria' 'Burkina Faso' 'Burundi' 'Cambodia' 'Cameroon' 'Canada'\n",
      " 'Cape Verde' 'Central African Republic' 'Chad' 'Chile' 'China' 'Colombia'\n",
      " 'Comoros' 'Congo, Dem. Rep.' 'Congo, Rep.' 'Cook Islands' 'Costa Rica'\n",
      " \"Cote d'Ivoire\" 'Croatia' 'Cuba' 'Cyprus' 'Czech Republic' 'Denmark'\n",
      " 'Djibouti' 'Dominica' 'Dominican Republic' 'Ecuador' 'Egypt'\n",
      " 'El Salvador' 'Equatorial Guinea' 'Eritrea' 'Estonia' 'Ethiopia' 'Fiji'\n",
      " 'Finland' 'France' 'French Polynesia' 'Gabon' 'Gambia' 'Georgia'\n",
      " 'Germany' 'Ghana' 'Greece' 'Grenada' 'Guatemala' 'Guinea' 'Guinea-Bissau'\n",
      " 'Guyana' 'Haiti' 'Honduras' 'Hong Kong, China' 'Hungary' 'Iceland'\n",
      " 'India' 'Indonesia' 'Iran (Islamic Republic of)' 'Iraq' 'Ireland'\n",
      " 'Israel' 'Italy' 'Jamaica' 'Japan' 'Jordan' 'Kazakhstan' 'Kenya'\n",
      " 'Kiribati' 'Korea, Dem. Rep.' 'Korea, Rep.' 'Kuwait' 'Kyrgyzstan'\n",
      " \"Lao People's Democratic Republic\" 'Latvia' 'Lebanon' 'Lesotho' 'Liberia'\n",
      " 'Libyan Arab Jamahiriya' 'Lithuania' 'Luxembourg' 'Macao, China'\n",
      " 'Macedonia' 'Madagascar' 'Malawi' 'Malaysia' 'Maldives' 'Mali' 'Malta'\n",
      " 'Marshall Islands' 'Mauritania' 'Mauritius' 'Mexico'\n",
      " 'Micronesia (Federated States of)' 'Moldova' 'Monaco' 'Mongolia'\n",
      " 'Montenegro' 'Morocco' 'Mozambique' 'Myanmar' 'Namibia' 'Nauru' 'Nepal'\n",
      " 'Netherlands' 'Netherlands Antilles' 'New Caledonia' 'New Zealand'\n",
      " 'Nicaragua' 'Niger' 'Nigeria' 'Niue' 'Norway' 'Oman' 'Pakistan' 'Palau'\n",
      " 'Panama' 'Papua New Guinea' 'Paraguay' 'Peru' 'Philippines' 'Poland'\n",
      " 'Portugal' 'Puerto Rico' 'Qatar' 'Romania' 'Russia' 'Rwanda'\n",
      " 'Saint Kitts and Nevis' 'Saint Lucia' 'Saint Vincent and the Grenadines'\n",
      " 'Samoa' 'San Marino' 'Sao Tome and Principe' 'Saudi Arabia' 'Senegal'\n",
      " 'Serbia' 'Seychelles' 'Sierra Leone' 'Singapore' 'Slovakia' 'Slovenia'\n",
      " 'Solomon Islands' 'Somalia' 'South Africa' 'Spain' 'Sri Lanka' 'Sudan'\n",
      " 'Suriname' 'Swaziland' 'Sweden' 'Switzerland' 'Syria' 'Taiwan'\n",
      " 'Tajikistan' 'Tanzania' 'Thailand' 'Timor-Leste' 'Togo' 'Tonga'\n",
      " 'Trinidad and Tobago' 'Tunisia' 'Turkey' 'Turkmenistan' 'Tuvalu' 'Uganda'\n",
      " 'Ukraine' 'United Arab Emirates' 'United Kingdom'\n",
      " 'United States of America' 'Uruguay' 'Uzbekistan' 'Vanuatu' 'Venezuela'\n",
      " 'Vietnam' 'West Bank and Gaza' 'Yemen' 'Zambia' 'Zimbabwe']\n"
     ]
    }
   ],
   "source": [
    "# Convert Pandas Series into List\n",
    "print(country_series.values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Country'"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Country name\n",
    "print(country_series.name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "197               Vietnam\n",
       "198    West Bank and Gaza\n",
       "199                 Yemen\n",
       "200                Zambia\n",
       "201              Zimbabwe\n",
       "Name: Country, dtype: object"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Pandas Series Slicing\n",
    "country_series[-5:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     Ajay\n",
       "1      Jay\n",
       "2    Vijay\n",
       "dtype: object"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Creating Pandas Series using Dictionary\n",
    "dict1 = {0 : 'Ajay', 1 : 'Jay', 2 : 'Vijay'}\n",
    "# Create Pandas Series\n",
    "series = pd.Series(dict1)\n",
    "# Show series\n",
    "series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    51\n",
       "1    65\n",
       "2    48\n",
       "3    59\n",
       "4    68\n",
       "dtype: int64"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# load Pandas and NumPy\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "# Create NumPy array\n",
    "arr = np.array([51,65,48,59, 68])\n",
    "# Create Pandas Series\n",
    "series = pd.Series(arr)\n",
    "series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    10\n",
       "1    10\n",
       "2    10\n",
       "3    10\n",
       "4    10\n",
       "5    10\n",
       "dtype: int64"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# load Pandas and NumPy\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "# Create Pandas Series\n",
    "series = pd.Series(10, index=[0, 1, 2, 3, 4, 5])\n",
    "series"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Querying Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting quandl\n",
      "  Downloading https://files.pythonhosted.org/packages/07/ab/8cd479fba8a9b197a43a0d55dd534b066fb8e5a0a04b5c0384cbc5d663aa/Quandl-3.5.0-py2.py3-none-any.whl\n",
      "Requirement already satisfied: six in /home/avinash/anaconda3/lib/python3.7/site-packages (from quandl) (1.14.0)\n",
      "Collecting inflection>=0.3.1 (from quandl)\n",
      "  Downloading https://files.pythonhosted.org/packages/52/c1/36be286d85dbd76527fb613527222a795d7c071da195fa916e7bf3cb03cb/inflection-0.4.0-py2.py3-none-any.whl\n",
      "Requirement already satisfied: pandas>=0.14 in /home/avinash/anaconda3/lib/python3.7/site-packages (from quandl) (0.24.2)\n",
      "Requirement already satisfied: more-itertools in /home/avinash/anaconda3/lib/python3.7/site-packages (from quandl) (6.0.0)\n",
      "Requirement already satisfied: requests>=2.7.0 in /home/avinash/anaconda3/lib/python3.7/site-packages (from quandl) (2.21.0)\n",
      "Requirement already satisfied: numpy>=1.8 in /home/avinash/anaconda3/lib/python3.7/site-packages (from quandl) (1.18.1)\n",
      "Requirement already satisfied: python-dateutil in /home/avinash/anaconda3/lib/python3.7/site-packages (from quandl) (2.8.0)\n",
      "Requirement already satisfied: pytz>=2011k in /home/avinash/anaconda3/lib/python3.7/site-packages (from pandas>=0.14->quandl) (2018.9)\n",
      "Requirement already satisfied: idna<2.9,>=2.5 in /home/avinash/anaconda3/lib/python3.7/site-packages (from requests>=2.7.0->quandl) (2.8)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /home/avinash/anaconda3/lib/python3.7/site-packages (from requests>=2.7.0->quandl) (2019.11.28)\n",
      "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /home/avinash/anaconda3/lib/python3.7/site-packages (from requests>=2.7.0->quandl) (3.0.4)\n",
      "Requirement already satisfied: urllib3<1.25,>=1.21.1 in /home/avinash/anaconda3/lib/python3.7/site-packages (from requests>=2.7.0->quandl) (1.24.1)\n",
      "Installing collected packages: inflection, quandl\n",
      "Successfully installed inflection-0.4.0 quandl-3.5.0\n"
     ]
    }
   ],
   "source": [
    "!pip install quandl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "metadata": {},
   "outputs": [
    {
     "ename": "LimitExceededError",
     "evalue": "(Status 429) (Quandl Error QELx01) You have exceeded the anonymous user limit of 50 calls per day. To make more calls today, please register for a free Quandl account and then include your API key with your requests.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mLimitExceededError\u001b[0m                        Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-204-c7876ced1a46>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mquandl\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mquandl\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"SIDC/SUNSPOTS_A\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhead\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/quandl/get.py\u001b[0m in \u001b[0;36mget\u001b[0;34m(dataset, **kwargs)\u001b[0m\n\u001b[1;32m     46\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mdataset_args\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'column_index'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     47\u001b[0m             \u001b[0mkwargs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0;34m'column_index'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdataset_args\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'column_index'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 48\u001b[0;31m         \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDataset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdataset_args\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'code'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhandle_column_not_found\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     49\u001b[0m     \u001b[0;31m# Array\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     50\u001b[0m     \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdataset\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/quandl/model/dataset.py\u001b[0m in \u001b[0;36mdata\u001b[0;34m(self, **options)\u001b[0m\n\u001b[1;32m     45\u001b[0m         \u001b[0mupdated_options\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mUtil\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmerge_options\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'params'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     46\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 47\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mData\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mupdated_options\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     48\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mNotFoundError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     49\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mhandle_not_found_error\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/quandl/operations/list.py\u001b[0m in \u001b[0;36mall\u001b[0;34m(cls, **options)\u001b[0m\n\u001b[1;32m     13\u001b[0m             \u001b[0moptions\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'params'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     14\u001b[0m         \u001b[0mpath\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mUtil\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconstructed_path\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcls\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlist_path\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moptions\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'params'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m         \u001b[0mr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mConnection\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'get'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpath\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     16\u001b[0m         \u001b[0mresponse_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjson\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     17\u001b[0m         \u001b[0mUtil\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvert_to_dates\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse_data\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/quandl/connection.py\u001b[0m in \u001b[0;36mrequest\u001b[0;34m(cls, http_verb, url, **options)\u001b[0m\n\u001b[1;32m     36\u001b[0m         \u001b[0mabs_url\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'%s/%s'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mApiConfig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapi_base\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0murl\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     37\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 38\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mcls\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute_request\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhttp_verb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mabs_url\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     39\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     40\u001b[0m     \u001b[0;34m@\u001b[0m\u001b[0mclassmethod\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/quandl/connection.py\u001b[0m in \u001b[0;36mexecute_request\u001b[0;34m(cls, http_verb, url, **options)\u001b[0m\n\u001b[1;32m     48\u001b[0m                                        **options)\n\u001b[1;32m     49\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstatus_code\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0;36m200\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstatus_code\u001b[0m \u001b[0;34m>=\u001b[0m \u001b[0;36m300\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 50\u001b[0;31m                 \u001b[0mcls\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhandle_api_error\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     51\u001b[0m             \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     52\u001b[0m                 \u001b[0;32mreturn\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/quandl/connection.py\u001b[0m in \u001b[0;36mhandle_api_error\u001b[0;34m(cls, resp)\u001b[0m\n\u001b[1;32m    112\u001b[0m         \u001b[0mklass\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0md_klass\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcode_letter\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mQuandlError\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    113\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 114\u001b[0;31m         \u001b[0;32mraise\u001b[0m \u001b[0mklass\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstatus_code\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mheaders\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcode\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mLimitExceededError\u001b[0m: (Status 429) (Quandl Error QELx01) You have exceeded the anonymous user limit of 50 calls per day. To make more calls today, please register for a free Quandl account and then include your API key with your requests."
     ]
    }
   ],
   "source": [
    "import quandl\n",
    "\n",
    "sunspots = quandl.get(\"SIDC/SUNSPOTS_A\")\n",
    "\n",
    "sunspots.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Yearly Mean Total Sunspot Number</th>\n",
       "      <th>Yearly Mean Standard Deviation</th>\n",
       "      <th>Number of Observations</th>\n",
       "      <th>Definitive/Provisional Indicator</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1700-12-31</th>\n",
       "      <td>8.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1701-12-31</th>\n",
       "      <td>18.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1702-12-31</th>\n",
       "      <td>26.7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1703-12-31</th>\n",
       "      <td>38.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1704-12-31</th>\n",
       "      <td>60.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            Yearly Mean Total Sunspot Number  Yearly Mean Standard Deviation  \\\n",
       "Date                                                                           \n",
       "1700-12-31                               8.3                             NaN   \n",
       "1701-12-31                              18.3                             NaN   \n",
       "1702-12-31                              26.7                             NaN   \n",
       "1703-12-31                              38.3                             NaN   \n",
       "1704-12-31                              60.0                             NaN   \n",
       "\n",
       "            Number of Observations  Definitive/Provisional Indicator  \n",
       "Date                                                                  \n",
       "1700-12-31                     NaN                               1.0  \n",
       "1701-12-31                     NaN                               1.0  \n",
       "1702-12-31                     NaN                               1.0  \n",
       "1703-12-31                     NaN                               1.0  \n",
       "1704-12-31                     NaN                               1.0  "
      ]
     },
     "execution_count": 207,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sunspots.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Yearly Mean Total Sunspot Number</th>\n",
       "      <th>Yearly Mean Standard Deviation</th>\n",
       "      <th>Number of Observations</th>\n",
       "      <th>Definitive/Provisional Indicator</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-12-31</th>\n",
       "      <td>69.8</td>\n",
       "      <td>6.4</td>\n",
       "      <td>8903.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-12-31</th>\n",
       "      <td>39.8</td>\n",
       "      <td>3.9</td>\n",
       "      <td>9940.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-12-31</th>\n",
       "      <td>21.7</td>\n",
       "      <td>2.5</td>\n",
       "      <td>11444.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-12-31</th>\n",
       "      <td>7.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>12611.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-12-31</th>\n",
       "      <td>3.6</td>\n",
       "      <td>0.5</td>\n",
       "      <td>12401.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            Yearly Mean Total Sunspot Number  Yearly Mean Standard Deviation  \\\n",
       "Date                                                                           \n",
       "2015-12-31                              69.8                             6.4   \n",
       "2016-12-31                              39.8                             3.9   \n",
       "2017-12-31                              21.7                             2.5   \n",
       "2018-12-31                               7.0                             1.1   \n",
       "2019-12-31                               3.6                             0.5   \n",
       "\n",
       "            Number of Observations  Definitive/Provisional Indicator  \n",
       "Date                                                                  \n",
       "2015-12-31                  8903.0                               1.0  \n",
       "2016-12-31                  9940.0                               1.0  \n",
       "2017-12-31                 11444.0                               1.0  \n",
       "2018-12-31                 12611.0                               1.0  \n",
       "2019-12-31                 12401.0                               0.0  "
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sunspots.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 210,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Yearly Mean Total Sunspot Number', 'Yearly Mean Standard Deviation',\n",
       "       'Number of Observations', 'Definitive/Provisional Indicator'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 210,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sunspots.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Yearly Mean Total Sunspot Number</th>\n",
       "      <th>Definitive/Provisional Indicator</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1700-12-31</th>\n",
       "      <td>8.3</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1701-12-31</th>\n",
       "      <td>18.3</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1702-12-31</th>\n",
       "      <td>26.7</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1703-12-31</th>\n",
       "      <td>38.3</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1704-12-31</th>\n",
       "      <td>60.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            Yearly Mean Total Sunspot Number  Definitive/Provisional Indicator\n",
       "Date                                                                          \n",
       "1700-12-31                               8.3                               1.0\n",
       "1701-12-31                              18.3                               1.0\n",
       "1702-12-31                              26.7                               1.0\n",
       "1703-12-31                              38.3                               1.0\n",
       "1704-12-31                              60.0                               1.0"
      ]
     },
     "execution_count": 212,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Select columns\n",
    "sunspots_filtered=sunspots[['Yearly Mean Total Sunspot Number','Definitive/Provisional Indicator']]\n",
    "\n",
    "# Show top 5 records\n",
    "sunspots_filtered.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Yearly Mean Total Sunspot Number</th>\n",
       "      <th>Yearly Mean Standard Deviation</th>\n",
       "      <th>Number of Observations</th>\n",
       "      <th>Definitive/Provisional Indicator</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2002-12-31</th>\n",
       "      <td>163.6</td>\n",
       "      <td>9.8</td>\n",
       "      <td>6588.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2003-12-31</th>\n",
       "      <td>99.3</td>\n",
       "      <td>7.1</td>\n",
       "      <td>7087.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2004-12-31</th>\n",
       "      <td>65.3</td>\n",
       "      <td>5.9</td>\n",
       "      <td>6882.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2005-12-31</th>\n",
       "      <td>45.8</td>\n",
       "      <td>4.7</td>\n",
       "      <td>7084.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2006-12-31</th>\n",
       "      <td>24.7</td>\n",
       "      <td>3.5</td>\n",
       "      <td>6370.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2007-12-31</th>\n",
       "      <td>12.6</td>\n",
       "      <td>2.7</td>\n",
       "      <td>6841.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-12-31</th>\n",
       "      <td>4.2</td>\n",
       "      <td>2.5</td>\n",
       "      <td>6644.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-12-31</th>\n",
       "      <td>4.8</td>\n",
       "      <td>2.5</td>\n",
       "      <td>6465.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-12-31</th>\n",
       "      <td>24.9</td>\n",
       "      <td>3.4</td>\n",
       "      <td>6328.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-12-31</th>\n",
       "      <td>80.8</td>\n",
       "      <td>6.7</td>\n",
       "      <td>6077.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-12-31</th>\n",
       "      <td>84.5</td>\n",
       "      <td>6.7</td>\n",
       "      <td>5753.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-12-31</th>\n",
       "      <td>94.0</td>\n",
       "      <td>6.9</td>\n",
       "      <td>5347.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            Yearly Mean Total Sunspot Number  Yearly Mean Standard Deviation  \\\n",
       "Date                                                                           \n",
       "2002-12-31                             163.6                             9.8   \n",
       "2003-12-31                              99.3                             7.1   \n",
       "2004-12-31                              65.3                             5.9   \n",
       "2005-12-31                              45.8                             4.7   \n",
       "2006-12-31                              24.7                             3.5   \n",
       "2007-12-31                              12.6                             2.7   \n",
       "2008-12-31                               4.2                             2.5   \n",
       "2009-12-31                               4.8                             2.5   \n",
       "2010-12-31                              24.9                             3.4   \n",
       "2011-12-31                              80.8                             6.7   \n",
       "2012-12-31                              84.5                             6.7   \n",
       "2013-12-31                              94.0                             6.9   \n",
       "\n",
       "            Number of Observations  Definitive/Provisional Indicator  \n",
       "Date                                                                  \n",
       "2002-12-31                  6588.0                               1.0  \n",
       "2003-12-31                  7087.0                               1.0  \n",
       "2004-12-31                  6882.0                               1.0  \n",
       "2005-12-31                  7084.0                               1.0  \n",
       "2006-12-31                  6370.0                               1.0  \n",
       "2007-12-31                  6841.0                               1.0  \n",
       "2008-12-31                  6644.0                               1.0  \n",
       "2009-12-31                  6465.0                               1.0  \n",
       "2010-12-31                  6328.0                               1.0  \n",
       "2011-12-31                  6077.0                               1.0  \n",
       "2012-12-31                  5753.0                               1.0  \n",
       "2013-12-31                  5347.0                               1.0  "
      ]
     },
     "execution_count": 213,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Select rows using index\n",
    "sunspots[\"20020101\": \"20131231\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 215,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Yearly Mean Total Sunspot Number</th>\n",
       "      <th>Yearly Mean Standard Deviation</th>\n",
       "      <th>Number of Observations</th>\n",
       "      <th>Definitive/Provisional Indicator</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1705-12-31</th>\n",
       "      <td>96.7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1717-12-31</th>\n",
       "      <td>105.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1718-12-31</th>\n",
       "      <td>100.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1726-12-31</th>\n",
       "      <td>130.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1727-12-31</th>\n",
       "      <td>203.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1728-12-31</th>\n",
       "      <td>171.7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1729-12-31</th>\n",
       "      <td>121.7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1736-12-31</th>\n",
       "      <td>116.7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1737-12-31</th>\n",
       "      <td>135.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1738-12-31</th>\n",
       "      <td>185.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1739-12-31</th>\n",
       "      <td>168.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1740-12-31</th>\n",
       "      <td>121.7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1748-12-31</th>\n",
       "      <td>100.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1749-12-31</th>\n",
       "      <td>134.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1750-12-31</th>\n",
       "      <td>139.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1751-12-31</th>\n",
       "      <td>79.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1752-12-31</th>\n",
       "      <td>79.7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1758-12-31</th>\n",
       "      <td>79.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1759-12-31</th>\n",
       "      <td>90.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1760-12-31</th>\n",
       "      <td>104.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1761-12-31</th>\n",
       "      <td>143.2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1762-12-31</th>\n",
       "      <td>102.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1768-12-31</th>\n",
       "      <td>116.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1769-12-31</th>\n",
       "      <td>176.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1770-12-31</th>\n",
       "      <td>168.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1771-12-31</th>\n",
       "      <td>136.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1772-12-31</th>\n",
       "      <td>110.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1777-12-31</th>\n",
       "      <td>154.2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1778-12-31</th>\n",
       "      <td>257.3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1779-12-31</th>\n",
       "      <td>209.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1958-12-31</th>\n",
       "      <td>261.7</td>\n",
       "      <td>10.8</td>\n",
       "      <td>365.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1959-12-31</th>\n",
       "      <td>225.1</td>\n",
       "      <td>10.0</td>\n",
       "      <td>365.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1960-12-31</th>\n",
       "      <td>159.0</td>\n",
       "      <td>8.4</td>\n",
       "      <td>366.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1967-12-31</th>\n",
       "      <td>132.9</td>\n",
       "      <td>7.7</td>\n",
       "      <td>365.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1968-12-31</th>\n",
       "      <td>150.0</td>\n",
       "      <td>8.2</td>\n",
       "      <td>366.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1969-12-31</th>\n",
       "      <td>149.4</td>\n",
       "      <td>8.2</td>\n",
       "      <td>365.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1970-12-31</th>\n",
       "      <td>148.0</td>\n",
       "      <td>8.1</td>\n",
       "      <td>365.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1971-12-31</th>\n",
       "      <td>94.4</td>\n",
       "      <td>6.5</td>\n",
       "      <td>365.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1972-12-31</th>\n",
       "      <td>97.6</td>\n",
       "      <td>6.6</td>\n",
       "      <td>366.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1978-12-31</th>\n",
       "      <td>131.0</td>\n",
       "      <td>7.6</td>\n",
       "      <td>365.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1979-12-31</th>\n",
       "      <td>220.1</td>\n",
       "      <td>9.9</td>\n",
       "      <td>365.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1980-12-31</th>\n",
       "      <td>218.9</td>\n",
       "      <td>9.9</td>\n",
       "      <td>366.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1981-12-31</th>\n",
       "      <td>198.9</td>\n",
       "      <td>13.1</td>\n",
       "      <td>3049.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1982-12-31</th>\n",
       "      <td>162.4</td>\n",
       "      <td>12.1</td>\n",
       "      <td>3436.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1983-12-31</th>\n",
       "      <td>91.0</td>\n",
       "      <td>7.6</td>\n",
       "      <td>4216.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1988-12-31</th>\n",
       "      <td>123.0</td>\n",
       "      <td>8.4</td>\n",
       "      <td>6556.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1989-12-31</th>\n",
       "      <td>211.1</td>\n",
       "      <td>12.8</td>\n",
       "      <td>6932.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-31</th>\n",
       "      <td>191.8</td>\n",
       "      <td>11.2</td>\n",
       "      <td>7108.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-12-31</th>\n",
       "      <td>203.3</td>\n",
       "      <td>12.7</td>\n",
       "      <td>6932.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1992-12-31</th>\n",
       "      <td>133.0</td>\n",
       "      <td>8.9</td>\n",
       "      <td>7845.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1998-12-31</th>\n",
       "      <td>88.3</td>\n",
       "      <td>6.6</td>\n",
       "      <td>6353.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1999-12-31</th>\n",
       "      <td>136.3</td>\n",
       "      <td>9.3</td>\n",
       "      <td>6413.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-12-31</th>\n",
       "      <td>173.9</td>\n",
       "      <td>10.1</td>\n",
       "      <td>5953.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2001-12-31</th>\n",
       "      <td>170.4</td>\n",
       "      <td>10.5</td>\n",
       "      <td>6558.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2002-12-31</th>\n",
       "      <td>163.6</td>\n",
       "      <td>9.8</td>\n",
       "      <td>6588.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2003-12-31</th>\n",
       "      <td>99.3</td>\n",
       "      <td>7.1</td>\n",
       "      <td>7087.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-12-31</th>\n",
       "      <td>80.8</td>\n",
       "      <td>6.7</td>\n",
       "      <td>6077.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-12-31</th>\n",
       "      <td>84.5</td>\n",
       "      <td>6.7</td>\n",
       "      <td>5753.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-12-31</th>\n",
       "      <td>94.0</td>\n",
       "      <td>6.9</td>\n",
       "      <td>5347.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2014-12-31</th>\n",
       "      <td>113.3</td>\n",
       "      <td>8.0</td>\n",
       "      <td>5273.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>136 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Yearly Mean Total Sunspot Number  Yearly Mean Standard Deviation  \\\n",
       "Date                                                                           \n",
       "1705-12-31                              96.7                             NaN   \n",
       "1717-12-31                             105.0                             NaN   \n",
       "1718-12-31                             100.0                             NaN   \n",
       "1726-12-31                             130.0                             NaN   \n",
       "1727-12-31                             203.3                             NaN   \n",
       "1728-12-31                             171.7                             NaN   \n",
       "1729-12-31                             121.7                             NaN   \n",
       "1736-12-31                             116.7                             NaN   \n",
       "1737-12-31                             135.0                             NaN   \n",
       "1738-12-31                             185.0                             NaN   \n",
       "1739-12-31                             168.3                             NaN   \n",
       "1740-12-31                             121.7                             NaN   \n",
       "1748-12-31                             100.0                             NaN   \n",
       "1749-12-31                             134.8                             NaN   \n",
       "1750-12-31                             139.0                             NaN   \n",
       "1751-12-31                              79.5                             NaN   \n",
       "1752-12-31                              79.7                             NaN   \n",
       "1758-12-31                              79.3                             NaN   \n",
       "1759-12-31                              90.0                             NaN   \n",
       "1760-12-31                             104.8                             NaN   \n",
       "1761-12-31                             143.2                             NaN   \n",
       "1762-12-31                             102.0                             NaN   \n",
       "1768-12-31                             116.3                             NaN   \n",
       "1769-12-31                             176.8                             NaN   \n",
       "1770-12-31                             168.0                             NaN   \n",
       "1771-12-31                             136.0                             NaN   \n",
       "1772-12-31                             110.8                             NaN   \n",
       "1777-12-31                             154.2                             NaN   \n",
       "1778-12-31                             257.3                             NaN   \n",
       "1779-12-31                             209.8                             NaN   \n",
       "...                                      ...                             ...   \n",
       "1958-12-31                             261.7                            10.8   \n",
       "1959-12-31                             225.1                            10.0   \n",
       "1960-12-31                             159.0                             8.4   \n",
       "1967-12-31                             132.9                             7.7   \n",
       "1968-12-31                             150.0                             8.2   \n",
       "1969-12-31                             149.4                             8.2   \n",
       "1970-12-31                             148.0                             8.1   \n",
       "1971-12-31                              94.4                             6.5   \n",
       "1972-12-31                              97.6                             6.6   \n",
       "1978-12-31                             131.0                             7.6   \n",
       "1979-12-31                             220.1                             9.9   \n",
       "1980-12-31                             218.9                             9.9   \n",
       "1981-12-31                             198.9                            13.1   \n",
       "1982-12-31                             162.4                            12.1   \n",
       "1983-12-31                              91.0                             7.6   \n",
       "1988-12-31                             123.0                             8.4   \n",
       "1989-12-31                             211.1                            12.8   \n",
       "1990-12-31                             191.8                            11.2   \n",
       "1991-12-31                             203.3                            12.7   \n",
       "1992-12-31                             133.0                             8.9   \n",
       "1998-12-31                              88.3                             6.6   \n",
       "1999-12-31                             136.3                             9.3   \n",
       "2000-12-31                             173.9                            10.1   \n",
       "2001-12-31                             170.4                            10.5   \n",
       "2002-12-31                             163.6                             9.8   \n",
       "2003-12-31                              99.3                             7.1   \n",
       "2011-12-31                              80.8                             6.7   \n",
       "2012-12-31                              84.5                             6.7   \n",
       "2013-12-31                              94.0                             6.9   \n",
       "2014-12-31                             113.3                             8.0   \n",
       "\n",
       "            Number of Observations  Definitive/Provisional Indicator  \n",
       "Date                                                                  \n",
       "1705-12-31                     NaN                               1.0  \n",
       "1717-12-31                     NaN                               1.0  \n",
       "1718-12-31                     NaN                               1.0  \n",
       "1726-12-31                     NaN                               1.0  \n",
       "1727-12-31                     NaN                               1.0  \n",
       "1728-12-31                     NaN                               1.0  \n",
       "1729-12-31                     NaN                               1.0  \n",
       "1736-12-31                     NaN                               1.0  \n",
       "1737-12-31                     NaN                               1.0  \n",
       "1738-12-31                     NaN                               1.0  \n",
       "1739-12-31                     NaN                               1.0  \n",
       "1740-12-31                     NaN                               1.0  \n",
       "1748-12-31                     NaN                               1.0  \n",
       "1749-12-31                     NaN                               1.0  \n",
       "1750-12-31                     NaN                               1.0  \n",
       "1751-12-31                     NaN                               1.0  \n",
       "1752-12-31                     NaN                               1.0  \n",
       "1758-12-31                     NaN                               1.0  \n",
       "1759-12-31                     NaN                               1.0  \n",
       "1760-12-31                     NaN                               1.0  \n",
       "1761-12-31                     NaN                               1.0  \n",
       "1762-12-31                     NaN                               1.0  \n",
       "1768-12-31                     NaN                               1.0  \n",
       "1769-12-31                     NaN                               1.0  \n",
       "1770-12-31                     NaN                               1.0  \n",
       "1771-12-31                     NaN                               1.0  \n",
       "1772-12-31                     NaN                               1.0  \n",
       "1777-12-31                     NaN                               1.0  \n",
       "1778-12-31                     NaN                               1.0  \n",
       "1779-12-31                     NaN                               1.0  \n",
       "...                            ...                               ...  \n",
       "1958-12-31                   365.0                               1.0  \n",
       "1959-12-31                   365.0                               1.0  \n",
       "1960-12-31                   366.0                               1.0  \n",
       "1967-12-31                   365.0                               1.0  \n",
       "1968-12-31                   366.0                               1.0  \n",
       "1969-12-31                   365.0                               1.0  \n",
       "1970-12-31                   365.0                               1.0  \n",
       "1971-12-31                   365.0                               1.0  \n",
       "1972-12-31                   366.0                               1.0  \n",
       "1978-12-31                   365.0                               1.0  \n",
       "1979-12-31                   365.0                               1.0  \n",
       "1980-12-31                   366.0                               1.0  \n",
       "1981-12-31                  3049.0                               1.0  \n",
       "1982-12-31                  3436.0                               1.0  \n",
       "1983-12-31                  4216.0                               1.0  \n",
       "1988-12-31                  6556.0                               1.0  \n",
       "1989-12-31                  6932.0                               1.0  \n",
       "1990-12-31                  7108.0                               1.0  \n",
       "1991-12-31                  6932.0                               1.0  \n",
       "1992-12-31                  7845.0                               1.0  \n",
       "1998-12-31                  6353.0                               1.0  \n",
       "1999-12-31                  6413.0                               1.0  \n",
       "2000-12-31                  5953.0                               1.0  \n",
       "2001-12-31                  6558.0                               1.0  \n",
       "2002-12-31                  6588.0                               1.0  \n",
       "2003-12-31                  7087.0                               1.0  \n",
       "2011-12-31                  6077.0                               1.0  \n",
       "2012-12-31                  5753.0                               1.0  \n",
       "2013-12-31                  5347.0                               1.0  \n",
       "2014-12-31                  5273.0                               1.0  \n",
       "\n",
       "[136 rows x 4 columns]"
      ]
     },
     "execution_count": 215,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Boolean Filter \n",
    "sunspots[sunspots['Yearly Mean Total Sunspot Number'] > sunspots['Yearly Mean Total Sunspot Number'].mean()]\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>CountryID</th>\n",
       "      <th>Continent</th>\n",
       "      <th>Adolescent fertility rate (%)</th>\n",
       "      <th>Adult literacy rate (%)</th>\n",
       "      <th>Gross national income per capita (PPP international $)</th>\n",
       "      <th>Net primary school enrolment ratio female (%)</th>\n",
       "      <th>Net primary school enrolment ratio male (%)</th>\n",
       "      <th>Population (in thousands) total</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>151.0</td>\n",
       "      <td>28.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26088.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Albania</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>27.0</td>\n",
       "      <td>98.7</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>93.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>3172.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Algeria</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>6.0</td>\n",
       "      <td>69.9</td>\n",
       "      <td>5940.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>96.0</td>\n",
       "      <td>33351.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Andorra</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>83.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>74.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Angola</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>146.0</td>\n",
       "      <td>67.4</td>\n",
       "      <td>3890.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>51.0</td>\n",
       "      <td>16557.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Country  CountryID  Continent  Adolescent fertility rate (%)  \\\n",
       "0  Afghanistan          1          1                          151.0   \n",
       "1      Albania          2          2                           27.0   \n",
       "2      Algeria          3          3                            6.0   \n",
       "3      Andorra          4          2                            NaN   \n",
       "4       Angola          5          3                          146.0   \n",
       "\n",
       "   Adult literacy rate (%)  \\\n",
       "0                     28.0   \n",
       "1                     98.7   \n",
       "2                     69.9   \n",
       "3                      NaN   \n",
       "4                     67.4   \n",
       "\n",
       "   Gross national income per capita (PPP international $)  \\\n",
       "0                                                NaN        \n",
       "1                                             6000.0        \n",
       "2                                             5940.0        \n",
       "3                                                NaN        \n",
       "4                                             3890.0        \n",
       "\n",
       "   Net primary school enrolment ratio female (%)  \\\n",
       "0                                            NaN   \n",
       "1                                           93.0   \n",
       "2                                           94.0   \n",
       "3                                           83.0   \n",
       "4                                           49.0   \n",
       "\n",
       "   Net primary school enrolment ratio male (%)  \\\n",
       "0                                          NaN   \n",
       "1                                         94.0   \n",
       "2                                         96.0   \n",
       "3                                         83.0   \n",
       "4                                         51.0   \n",
       "\n",
       "   Population (in thousands) total  \n",
       "0                          26088.0  \n",
       "1                           3172.0  \n",
       "2                          33351.0  \n",
       "3                             74.0  \n",
       "4                          16557.0  "
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Import pandas \n",
    "import pandas as pd\n",
    "\n",
    "# Load data using read_csv() \n",
    "df = pd.read_csv(\"WHO_first9cols.csv\")\n",
    "\n",
    "# Show initial 5 records\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(202, 9)"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CountryID</th>\n",
       "      <th>Continent</th>\n",
       "      <th>Adolescent fertility rate (%)</th>\n",
       "      <th>Adult literacy rate (%)</th>\n",
       "      <th>Gross national income per capita (PPP international $)</th>\n",
       "      <th>Net primary school enrolment ratio female (%)</th>\n",
       "      <th>Net primary school enrolment ratio male (%)</th>\n",
       "      <th>Population (in thousands) total</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>202.000000</td>\n",
       "      <td>202.000000</td>\n",
       "      <td>177.000000</td>\n",
       "      <td>131.000000</td>\n",
       "      <td>178.000000</td>\n",
       "      <td>179.000000</td>\n",
       "      <td>179.000000</td>\n",
       "      <td>1.890000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>101.500000</td>\n",
       "      <td>3.579208</td>\n",
       "      <td>59.457627</td>\n",
       "      <td>78.871756</td>\n",
       "      <td>11250.112360</td>\n",
       "      <td>84.033520</td>\n",
       "      <td>85.698324</td>\n",
       "      <td>3.409964e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>58.456537</td>\n",
       "      <td>1.808263</td>\n",
       "      <td>49.105286</td>\n",
       "      <td>20.415760</td>\n",
       "      <td>12586.753417</td>\n",
       "      <td>17.788047</td>\n",
       "      <td>15.451212</td>\n",
       "      <td>1.318377e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>23.600000</td>\n",
       "      <td>260.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>2.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>51.250000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>19.000000</td>\n",
       "      <td>68.400000</td>\n",
       "      <td>2112.500000</td>\n",
       "      <td>79.000000</td>\n",
       "      <td>79.500000</td>\n",
       "      <td>1.328000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>101.500000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>46.000000</td>\n",
       "      <td>86.500000</td>\n",
       "      <td>6175.000000</td>\n",
       "      <td>90.000000</td>\n",
       "      <td>90.000000</td>\n",
       "      <td>6.640000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>151.750000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>91.000000</td>\n",
       "      <td>95.300000</td>\n",
       "      <td>14502.500000</td>\n",
       "      <td>96.000000</td>\n",
       "      <td>96.000000</td>\n",
       "      <td>2.097100e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>202.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>199.000000</td>\n",
       "      <td>99.800000</td>\n",
       "      <td>60870.000000</td>\n",
       "      <td>100.000000</td>\n",
       "      <td>100.000000</td>\n",
       "      <td>1.328474e+06</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        CountryID   Continent  Adolescent fertility rate (%)  \\\n",
       "count  202.000000  202.000000                     177.000000   \n",
       "mean   101.500000    3.579208                      59.457627   \n",
       "std     58.456537    1.808263                      49.105286   \n",
       "min      1.000000    1.000000                       0.000000   \n",
       "25%     51.250000    2.000000                      19.000000   \n",
       "50%    101.500000    3.000000                      46.000000   \n",
       "75%    151.750000    5.000000                      91.000000   \n",
       "max    202.000000    7.000000                     199.000000   \n",
       "\n",
       "       Adult literacy rate (%)  \\\n",
       "count               131.000000   \n",
       "mean                 78.871756   \n",
       "std                  20.415760   \n",
       "min                  23.600000   \n",
       "25%                  68.400000   \n",
       "50%                  86.500000   \n",
       "75%                  95.300000   \n",
       "max                  99.800000   \n",
       "\n",
       "       Gross national income per capita (PPP international $)  \\\n",
       "count                                         178.000000        \n",
       "mean                                        11250.112360        \n",
       "std                                         12586.753417        \n",
       "min                                           260.000000        \n",
       "25%                                          2112.500000        \n",
       "50%                                          6175.000000        \n",
       "75%                                         14502.500000        \n",
       "max                                         60870.000000        \n",
       "\n",
       "       Net primary school enrolment ratio female (%)  \\\n",
       "count                                     179.000000   \n",
       "mean                                       84.033520   \n",
       "std                                        17.788047   \n",
       "min                                         6.000000   \n",
       "25%                                        79.000000   \n",
       "50%                                        90.000000   \n",
       "75%                                        96.000000   \n",
       "max                                       100.000000   \n",
       "\n",
       "       Net primary school enrolment ratio male (%)  \\\n",
       "count                                   179.000000   \n",
       "mean                                     85.698324   \n",
       "std                                      15.451212   \n",
       "min                                      11.000000   \n",
       "25%                                      79.500000   \n",
       "50%                                      90.000000   \n",
       "75%                                      96.000000   \n",
       "max                                     100.000000   \n",
       "\n",
       "       Population (in thousands) total  \n",
       "count                     1.890000e+02  \n",
       "mean                      3.409964e+04  \n",
       "std                       1.318377e+05  \n",
       "min                       2.000000e+00  \n",
       "25%                       1.328000e+03  \n",
       "50%                       6.640000e+03  \n",
       "75%                       2.097100e+04  \n",
       "max                       1.328474e+06  "
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Describe the dataset\n",
    "df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Country                                                   202\n",
       "CountryID                                                 202\n",
       "Continent                                                 202\n",
       "Adolescent fertility rate (%)                             177\n",
       "Adult literacy rate (%)                                   131\n",
       "Gross national income per capita (PPP international $)    178\n",
       "Net primary school enrolment ratio female (%)             179\n",
       "Net primary school enrolment ratio male (%)               179\n",
       "Population (in thousands) total                           189\n",
       "dtype: int64"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Count number of observation\n",
    "df.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "CountryID                                                  101.5\n",
       "Continent                                                    3.0\n",
       "Adolescent fertility rate (%)                               46.0\n",
       "Adult literacy rate (%)                                     86.5\n",
       "Gross national income per capita (PPP international $)    6175.0\n",
       "Net primary school enrolment ratio female (%)               90.0\n",
       "Net primary school enrolment ratio male (%)                 90.0\n",
       "Population (in thousands) total                           6640.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Compute median of all the columns\n",
    "df.median()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Country                                                   Afghanistan\n",
       "CountryID                                                           1\n",
       "Continent                                                           1\n",
       "Adolescent fertility rate (%)                                       0\n",
       "Adult literacy rate (%)                                          23.6\n",
       "Gross national income per capita (PPP international $)            260\n",
       "Net primary school enrolment ratio female (%)                       6\n",
       "Net primary school enrolment ratio male (%)                        11\n",
       "Population (in thousands) total                                     2\n",
       "dtype: object"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Compute minimum of all the columns\n",
    "df.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Country                                                      Zimbabwe\n",
       "CountryID                                                         202\n",
       "Continent                                                           7\n",
       "Adolescent fertility rate (%)                                     199\n",
       "Adult literacy rate (%)                                          99.8\n",
       "Gross national income per capita (PPP international $)          60870\n",
       "Net primary school enrolment ratio female (%)                     100\n",
       "Net primary school enrolment ratio male (%)                       100\n",
       "Population (in thousands) total                           1.32847e+06\n",
       "dtype: object"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Compute maximum of all the columns\n",
    "df.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "CountryID                                                     58.456537\n",
       "Continent                                                      1.808263\n",
       "Adolescent fertility rate (%)                                 49.105286\n",
       "Adult literacy rate (%)                                       20.415760\n",
       "Gross national income per capita (PPP international $)     12586.753417\n",
       "Net primary school enrolment ratio female (%)                 17.788047\n",
       "Net primary school enrolment ratio male (%)                   15.451212\n",
       "Population (in thousands) total                           131837.708677\n",
       "dtype: float64"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Compute standard deviation of all the columns\n",
    "df.std()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Grouping Pandas DataFrames"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>CountryID</th>\n",
       "      <th>Continent</th>\n",
       "      <th>Adolescent fertility rate (%)</th>\n",
       "      <th>Adult literacy rate (%)</th>\n",
       "      <th>Gross national income per capita (PPP international $)</th>\n",
       "      <th>Net primary school enrolment ratio female (%)</th>\n",
       "      <th>Net primary school enrolment ratio male (%)</th>\n",
       "      <th>Population (in thousands) total</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>151.0</td>\n",
       "      <td>28.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26088.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Albania</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>27.0</td>\n",
       "      <td>98.7</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>93.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>3172.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Algeria</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>6.0</td>\n",
       "      <td>69.9</td>\n",
       "      <td>5940.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>96.0</td>\n",
       "      <td>33351.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Andorra</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>83.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>74.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Angola</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>146.0</td>\n",
       "      <td>67.4</td>\n",
       "      <td>3890.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>51.0</td>\n",
       "      <td>16557.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Country  CountryID  Continent  Adolescent fertility rate (%)  \\\n",
       "0  Afghanistan          1          1                          151.0   \n",
       "1      Albania          2          2                           27.0   \n",
       "2      Algeria          3          3                            6.0   \n",
       "3      Andorra          4          2                            NaN   \n",
       "4       Angola          5          3                          146.0   \n",
       "\n",
       "   Adult literacy rate (%)  \\\n",
       "0                     28.0   \n",
       "1                     98.7   \n",
       "2                     69.9   \n",
       "3                      NaN   \n",
       "4                     67.4   \n",
       "\n",
       "   Gross national income per capita (PPP international $)  \\\n",
       "0                                                NaN        \n",
       "1                                             6000.0        \n",
       "2                                             5940.0        \n",
       "3                                                NaN        \n",
       "4                                             3890.0        \n",
       "\n",
       "   Net primary school enrolment ratio female (%)  \\\n",
       "0                                            NaN   \n",
       "1                                           93.0   \n",
       "2                                           94.0   \n",
       "3                                           83.0   \n",
       "4                                           49.0   \n",
       "\n",
       "   Net primary school enrolment ratio male (%)  \\\n",
       "0                                          NaN   \n",
       "1                                         94.0   \n",
       "2                                         96.0   \n",
       "3                                         83.0   \n",
       "4                                         51.0   \n",
       "\n",
       "   Population (in thousands) total  \n",
       "0                          26088.0  \n",
       "1                           3172.0  \n",
       "2                          33351.0  \n",
       "3                             74.0  \n",
       "4                          16557.0  "
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CountryID</th>\n",
       "      <th>Adolescent fertility rate (%)</th>\n",
       "      <th>Adult literacy rate (%)</th>\n",
       "      <th>Gross national income per capita (PPP international $)</th>\n",
       "      <th>Net primary school enrolment ratio female (%)</th>\n",
       "      <th>Net primary school enrolment ratio male (%)</th>\n",
       "      <th>Population (in thousands) total</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Continent</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>110.238095</td>\n",
       "      <td>37.300000</td>\n",
       "      <td>76.900000</td>\n",
       "      <td>14893.529412</td>\n",
       "      <td>85.789474</td>\n",
       "      <td>88.315789</td>\n",
       "      <td>16843.350000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100.333333</td>\n",
       "      <td>20.500000</td>\n",
       "      <td>97.911538</td>\n",
       "      <td>19777.083333</td>\n",
       "      <td>92.911111</td>\n",
       "      <td>93.088889</td>\n",
       "      <td>17259.627451</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>99.354167</td>\n",
       "      <td>111.644444</td>\n",
       "      <td>61.690476</td>\n",
       "      <td>3050.434783</td>\n",
       "      <td>67.574468</td>\n",
       "      <td>72.021277</td>\n",
       "      <td>16503.195652</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>56.285714</td>\n",
       "      <td>49.600000</td>\n",
       "      <td>91.600000</td>\n",
       "      <td>24524.000000</td>\n",
       "      <td>95.000000</td>\n",
       "      <td>94.400000</td>\n",
       "      <td>73577.333333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>94.774194</td>\n",
       "      <td>77.888889</td>\n",
       "      <td>87.940909</td>\n",
       "      <td>7397.142857</td>\n",
       "      <td>89.137931</td>\n",
       "      <td>88.517241</td>\n",
       "      <td>15637.241379</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>121.228571</td>\n",
       "      <td>39.260870</td>\n",
       "      <td>87.607143</td>\n",
       "      <td>12167.200000</td>\n",
       "      <td>89.040000</td>\n",
       "      <td>89.960000</td>\n",
       "      <td>25517.142857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>80.777778</td>\n",
       "      <td>57.333333</td>\n",
       "      <td>69.812500</td>\n",
       "      <td>2865.555556</td>\n",
       "      <td>85.444444</td>\n",
       "      <td>88.888889</td>\n",
       "      <td>317683.666667</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            CountryID  Adolescent fertility rate (%)  Adult literacy rate (%)  \\\n",
       "Continent                                                                       \n",
       "1          110.238095                      37.300000                76.900000   \n",
       "2          100.333333                      20.500000                97.911538   \n",
       "3           99.354167                     111.644444                61.690476   \n",
       "4           56.285714                      49.600000                91.600000   \n",
       "5           94.774194                      77.888889                87.940909   \n",
       "6          121.228571                      39.260870                87.607143   \n",
       "7           80.777778                      57.333333                69.812500   \n",
       "\n",
       "           Gross national income per capita (PPP international $)  \\\n",
       "Continent                                                           \n",
       "1                                               14893.529412        \n",
       "2                                               19777.083333        \n",
       "3                                                3050.434783        \n",
       "4                                               24524.000000        \n",
       "5                                                7397.142857        \n",
       "6                                               12167.200000        \n",
       "7                                                2865.555556        \n",
       "\n",
       "           Net primary school enrolment ratio female (%)  \\\n",
       "Continent                                                  \n",
       "1                                              85.789474   \n",
       "2                                              92.911111   \n",
       "3                                              67.574468   \n",
       "4                                              95.000000   \n",
       "5                                              89.137931   \n",
       "6                                              89.040000   \n",
       "7                                              85.444444   \n",
       "\n",
       "           Net primary school enrolment ratio male (%)  \\\n",
       "Continent                                                \n",
       "1                                            88.315789   \n",
       "2                                            93.088889   \n",
       "3                                            72.021277   \n",
       "4                                            94.400000   \n",
       "5                                            88.517241   \n",
       "6                                            89.960000   \n",
       "7                                            88.888889   \n",
       "\n",
       "           Population (in thousands) total  \n",
       "Continent                                   \n",
       "1                             16843.350000  \n",
       "2                             17259.627451  \n",
       "3                             16503.195652  \n",
       "4                             73577.333333  \n",
       "5                             15637.241379  \n",
       "6                             25517.142857  \n",
       "7                            317683.666667  "
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Group By Dataframe on the basis of Continent column\n",
    "df.groupby('Continent').mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Continent\n",
       "1    76.900000\n",
       "2    97.911538\n",
       "3    61.690476\n",
       "4    91.600000\n",
       "5    87.940909\n",
       "6    87.607143\n",
       "7    69.812500\n",
       "Name: Adult literacy rate (%), dtype: float64"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('Continent').mean()['Adult literacy rate (%)']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Joins"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EmpNr</th>\n",
       "      <th>Dest</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5</td>\n",
       "      <td>The Hague</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>Amsterdam</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9</td>\n",
       "      <td>Rotterdam</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   EmpNr       Dest\n",
       "0      5  The Hague\n",
       "1      3  Amsterdam\n",
       "2      9  Rotterdam"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Import pandas \n",
    "import pandas as pd\n",
    "\n",
    "# Load data using read_csv() \n",
    "dest = pd.read_csv(\"dest.csv\")\n",
    "\n",
    "# Show DataFrame\n",
    "dest.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EmpNr</th>\n",
       "      <th>Amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7</td>\n",
       "      <td>2.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   EmpNr  Amount\n",
       "0      5    10.0\n",
       "1      9     5.0\n",
       "2      7     2.5"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Load data using read_csv() \n",
    "tips = pd.read_csv(\"tips.csv\")\n",
    "\n",
    "# Show DataFrame\n",
    "tips.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EmpNr</th>\n",
       "      <th>Dest</th>\n",
       "      <th>Amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5</td>\n",
       "      <td>The Hague</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   EmpNr       Dest  Amount\n",
       "0      5  The Hague    10.0\n",
       "1      9  Rotterdam     5.0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Join DataFrames using Inner Join\n",
    "df_inner= pd.merge(dest, tips, on='EmpNr', how='inner')\n",
    "df_inner.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EmpNr</th>\n",
       "      <th>Dest</th>\n",
       "      <th>Amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5</td>\n",
       "      <td>The Hague</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>Amsterdam</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   EmpNr       Dest  Amount\n",
       "0      5  The Hague    10.0\n",
       "1      3  Amsterdam     NaN\n",
       "2      9  Rotterdam     5.0\n",
       "3      7        NaN     2.5"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Join DataFrames using Outer Join\n",
    "df_outer= pd.merge(dest, tips, on='EmpNr', how='outer')\n",
    "df_outer.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EmpNr</th>\n",
       "      <th>Dest</th>\n",
       "      <th>Amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5</td>\n",
       "      <td>The Hague</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   EmpNr       Dest  Amount\n",
       "0      5  The Hague    10.0\n",
       "1      9  Rotterdam     5.0\n",
       "2      7        NaN     2.5"
      ]
     },
     "execution_count": 172,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Join DataFrames using Right Outer Join\n",
    "df_right= pd.merge(dest, tips, on='EmpNr', how='right')\n",
    "df_right"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EmpNr</th>\n",
       "      <th>Dest</th>\n",
       "      <th>Amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5</td>\n",
       "      <td>The Hague</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>Amsterdam</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9</td>\n",
       "      <td>Rotterdam</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   EmpNr       Dest  Amount\n",
       "0      5  The Hague    10.0\n",
       "1      3  Amsterdam     NaN\n",
       "2      9  Rotterdam     5.0"
      ]
     },
     "execution_count": 174,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Join DataFrames using Left Outer Join\n",
    "df_left= pd.merge(dest, tips, on='EmpNr', how='left')\n",
    "df_left"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Missing Values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>CountryID</th>\n",
       "      <th>Continent</th>\n",
       "      <th>Adolescent fertility rate (%)</th>\n",
       "      <th>Adult literacy rate (%)</th>\n",
       "      <th>Gross national income per capita (PPP international $)</th>\n",
       "      <th>Net primary school enrolment ratio female (%)</th>\n",
       "      <th>Net primary school enrolment ratio male (%)</th>\n",
       "      <th>Population (in thousands) total</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>151.0</td>\n",
       "      <td>28.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26088.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Albania</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>27.0</td>\n",
       "      <td>98.7</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>93.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>3172.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Algeria</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>6.0</td>\n",
       "      <td>69.9</td>\n",
       "      <td>5940.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>96.0</td>\n",
       "      <td>33351.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Andorra</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>83.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>74.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Angola</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>146.0</td>\n",
       "      <td>67.4</td>\n",
       "      <td>3890.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>51.0</td>\n",
       "      <td>16557.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Country  CountryID  Continent  Adolescent fertility rate (%)  \\\n",
       "0  Afghanistan          1          1                          151.0   \n",
       "1      Albania          2          2                           27.0   \n",
       "2      Algeria          3          3                            6.0   \n",
       "3      Andorra          4          2                            NaN   \n",
       "4       Angola          5          3                          146.0   \n",
       "\n",
       "   Adult literacy rate (%)  \\\n",
       "0                     28.0   \n",
       "1                     98.7   \n",
       "2                     69.9   \n",
       "3                      NaN   \n",
       "4                     67.4   \n",
       "\n",
       "   Gross national income per capita (PPP international $)  \\\n",
       "0                                                NaN        \n",
       "1                                             6000.0        \n",
       "2                                             5940.0        \n",
       "3                                                NaN        \n",
       "4                                             3890.0        \n",
       "\n",
       "   Net primary school enrolment ratio female (%)  \\\n",
       "0                                            NaN   \n",
       "1                                           93.0   \n",
       "2                                           94.0   \n",
       "3                                           83.0   \n",
       "4                                           49.0   \n",
       "\n",
       "   Net primary school enrolment ratio male (%)  \\\n",
       "0                                          NaN   \n",
       "1                                         94.0   \n",
       "2                                         96.0   \n",
       "3                                         83.0   \n",
       "4                                         51.0   \n",
       "\n",
       "   Population (in thousands) total  \n",
       "0                          26088.0  \n",
       "1                           3172.0  \n",
       "2                          33351.0  \n",
       "3                             74.0  \n",
       "4                          16557.0  "
      ]
     },
     "execution_count": 175,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Import pandas \n",
    "import pandas as pd\n",
    "\n",
    "# Load data using read_csv() \n",
    "df = pd.read_csv(\"WHO_first9cols.csv\")\n",
    "\n",
    "# Show initial 5 records\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Country                                                    0\n",
       "CountryID                                                  0\n",
       "Continent                                                  0\n",
       "Adolescent fertility rate (%)                             25\n",
       "Adult literacy rate (%)                                   71\n",
       "Gross national income per capita (PPP international $)    24\n",
       "Net primary school enrolment ratio female (%)             23\n",
       "Net primary school enrolment ratio male (%)               23\n",
       "Population (in thousands) total                           13\n",
       "dtype: int64"
      ]
     },
     "execution_count": 177,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Count missing values in DataFrame\n",
    "pd.isnull(df).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Country                                                    0\n",
       "CountryID                                                  0\n",
       "Continent                                                  0\n",
       "Adolescent fertility rate (%)                             25\n",
       "Adult literacy rate (%)                                   71\n",
       "Gross national income per capita (PPP international $)    24\n",
       "Net primary school enrolment ratio female (%)             23\n",
       "Net primary school enrolment ratio male (%)               23\n",
       "Population (in thousands) total                           13\n",
       "dtype: int64"
      ]
     },
     "execution_count": 178,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Count missing values in DataFrame\n",
    "df.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 202 entries, 0 to 201\n",
      "Data columns (total 9 columns):\n",
      "Country                                                   202 non-null object\n",
      "CountryID                                                 202 non-null int64\n",
      "Continent                                                 202 non-null int64\n",
      "Adolescent fertility rate (%)                             177 non-null float64\n",
      "Adult literacy rate (%)                                   131 non-null float64\n",
      "Gross national income per capita (PPP international $)    178 non-null float64\n",
      "Net primary school enrolment ratio female (%)             179 non-null float64\n",
      "Net primary school enrolment ratio male (%)               179 non-null float64\n",
      "Population (in thousands) total                           189 non-null float64\n",
      "dtypes: float64(6), int64(2), object(1)\n",
      "memory usage: 14.3+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Drop all the missing values\n",
    "df.dropna(inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 118 entries, 1 to 200\n",
      "Data columns (total 9 columns):\n",
      "Country                                                   118 non-null object\n",
      "CountryID                                                 118 non-null int64\n",
      "Continent                                                 118 non-null int64\n",
      "Adolescent fertility rate (%)                             118 non-null float64\n",
      "Adult literacy rate (%)                                   118 non-null float64\n",
      "Gross national income per capita (PPP international $)    118 non-null float64\n",
      "Net primary school enrolment ratio female (%)             118 non-null float64\n",
      "Net primary school enrolment ratio male (%)               118 non-null float64\n",
      "Population (in thousands) total                           118 non-null float64\n",
      "dtypes: float64(6), int64(2), object(1)\n",
      "memory usage: 9.2+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country</th>\n",
       "      <th>CountryID</th>\n",
       "      <th>Continent</th>\n",
       "      <th>Adolescent fertility rate (%)</th>\n",
       "      <th>Adult literacy rate (%)</th>\n",
       "      <th>Gross national income per capita (PPP international $)</th>\n",
       "      <th>Net primary school enrolment ratio female (%)</th>\n",
       "      <th>Net primary school enrolment ratio male (%)</th>\n",
       "      <th>Population (in thousands) total</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Afghanistan</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>151.0</td>\n",
       "      <td>28.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26088.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Albania</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>27.0</td>\n",
       "      <td>98.7</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>93.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>3172.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Algeria</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>6.0</td>\n",
       "      <td>69.9</td>\n",
       "      <td>5940.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>96.0</td>\n",
       "      <td>33351.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Andorra</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>83.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>74.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Angola</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>146.0</td>\n",
       "      <td>67.4</td>\n",
       "      <td>3890.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>51.0</td>\n",
       "      <td>16557.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Country  CountryID  Continent  Adolescent fertility rate (%)  \\\n",
       "0  Afghanistan          1          1                          151.0   \n",
       "1      Albania          2          2                           27.0   \n",
       "2      Algeria          3          3                            6.0   \n",
       "3      Andorra          4          2                            NaN   \n",
       "4       Angola          5          3                          146.0   \n",
       "\n",
       "   Adult literacy rate (%)  \\\n",
       "0                     28.0   \n",
       "1                     98.7   \n",
       "2                     69.9   \n",
       "3                      NaN   \n",
       "4                     67.4   \n",
       "\n",
       "   Gross national income per capita (PPP international $)  \\\n",
       "0                                                NaN        \n",
       "1                                             6000.0        \n",
       "2                                             5940.0        \n",
       "3                                                NaN        \n",
       "4                                             3890.0        \n",
       "\n",
       "   Net primary school enrolment ratio female (%)  \\\n",
       "0                                            NaN   \n",
       "1                                           93.0   \n",
       "2                                           94.0   \n",
       "3                                           83.0   \n",
       "4                                           49.0   \n",
       "\n",
       "   Net primary school enrolment ratio male (%)  \\\n",
       "0                                          NaN   \n",
       "1                                         94.0   \n",
       "2                                         96.0   \n",
       "3                                         83.0   \n",
       "4                                         51.0   \n",
       "\n",
       "   Population (in thousands) total  \n",
       "0                          26088.0  \n",
       "1                           3172.0  \n",
       "2                          33351.0  \n",
       "3                             74.0  \n",
       "4                          16557.0  "
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Load data using read_csv() \n",
    "df = pd.read_csv(\"WHO_first9cols.csv\")\n",
    "\n",
    "# Show initial 5 records\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 202 entries, 0 to 201\n",
      "Data columns (total 9 columns):\n",
      "Country                                                   202 non-null object\n",
      "CountryID                                                 202 non-null int64\n",
      "Continent                                                 202 non-null int64\n",
      "Adolescent fertility rate (%)                             177 non-null float64\n",
      "Adult literacy rate (%)                                   131 non-null float64\n",
      "Gross national income per capita (PPP international $)    178 non-null float64\n",
      "Net primary school enrolment ratio female (%)             179 non-null float64\n",
      "Net primary school enrolment ratio male (%)               179 non-null float64\n",
      "Population (in thousands) total                           189 non-null float64\n",
      "dtypes: float64(6), int64(2), object(1)\n",
      "memory usage: 14.3+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Fill missing values with 0\n",
    "df.fillna(0,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 202 entries, 0 to 201\n",
      "Data columns (total 9 columns):\n",
      "Country                                                   202 non-null object\n",
      "CountryID                                                 202 non-null int64\n",
      "Continent                                                 202 non-null int64\n",
      "Adolescent fertility rate (%)                             202 non-null float64\n",
      "Adult literacy rate (%)                                   202 non-null float64\n",
      "Gross national income per capita (PPP international $)    202 non-null float64\n",
      "Net primary school enrolment ratio female (%)             202 non-null float64\n",
      "Net primary school enrolment ratio male (%)               202 non-null float64\n",
      "Population (in thousands) total                           202 non-null float64\n",
      "dtypes: float64(6), int64(2), object(1)\n",
      "memory usage: 14.3+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pivot Table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Weather</th>\n",
       "      <th>Food</th>\n",
       "      <th>Price</th>\n",
       "      <th>Number</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>cold</td>\n",
       "      <td>soup</td>\n",
       "      <td>3.745401</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>hot</td>\n",
       "      <td>soup</td>\n",
       "      <td>9.507143</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>cold</td>\n",
       "      <td>icecream</td>\n",
       "      <td>7.319939</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>hot</td>\n",
       "      <td>chocolate</td>\n",
       "      <td>5.986585</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>cold</td>\n",
       "      <td>icecream</td>\n",
       "      <td>1.560186</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>hot</td>\n",
       "      <td>icecream</td>\n",
       "      <td>1.559945</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>cold</td>\n",
       "      <td>soup</td>\n",
       "      <td>0.580836</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Weather       Food     Price  Number\n",
       "0    cold       soup  3.745401       8\n",
       "1     hot       soup  9.507143       8\n",
       "2    cold   icecream  7.319939       8\n",
       "3     hot  chocolate  5.986585       8\n",
       "4    cold   icecream  1.560186       8\n",
       "5     hot   icecream  1.559945       8\n",
       "6    cold       soup  0.580836       8"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Import pandas \n",
    "import pandas as pd\n",
    "\n",
    "# Load data using read_csv() \n",
    "purchase = pd.read_csv(\"purchase.csv\")\n",
    "\n",
    "# Show initial 10 records\n",
    "purchase.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>Food</th>\n",
       "      <th>chocolate</th>\n",
       "      <th>icecream</th>\n",
       "      <th>soup</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Weather</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>cold</th>\n",
       "      <td>NaN</td>\n",
       "      <td>16.0</td>\n",
       "      <td>16.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>hot</th>\n",
       "      <td>8.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Food     chocolate  icecream  soup\n",
       "Weather                           \n",
       "cold           NaN      16.0  16.0\n",
       "hot            8.0       8.0   8.0"
      ]
     },
     "execution_count": 197,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Summarise dataframe using pivot table\n",
    "pd.pivot_table(purchase,values='Number', index=['Weather',],\n",
    "                    columns=['Food'], aggfunc=np.sum)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Dealing with dates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-03', '2000-01-04',\n",
       "               '2000-01-05', '2000-01-06', '2000-01-07', '2000-01-08',\n",
       "               '2000-01-09', '2000-01-10', '2000-01-11', '2000-01-12',\n",
       "               '2000-01-13', '2000-01-14', '2000-01-15', '2000-01-16',\n",
       "               '2000-01-17', '2000-01-18', '2000-01-19', '2000-01-20',\n",
       "               '2000-01-21', '2000-01-22', '2000-01-23', '2000-01-24',\n",
       "               '2000-01-25', '2000-01-26', '2000-01-27', '2000-01-28',\n",
       "               '2000-01-29', '2000-01-30', '2000-01-31', '2000-02-01',\n",
       "               '2000-02-02', '2000-02-03', '2000-02-04', '2000-02-05',\n",
       "               '2000-02-06', '2000-02-07', '2000-02-08', '2000-02-09',\n",
       "               '2000-02-10', '2000-02-11', '2000-02-12', '2000-02-13',\n",
       "               '2000-02-14'],\n",
       "              dtype='datetime64[ns]', freq='D')"
      ]
     },
     "execution_count": 217,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Date range function\n",
    "pd.date_range('01-01-2000', periods=45, freq='D')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('1970-01-01 00:00:00')"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Convert argument to datetime\n",
    "pd.to_datetime('1/1/1970')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2020-01-01', '2020-01-02'], dtype='datetime64[ns]', freq=None)"
      ]
     },
     "execution_count": 223,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Convert argument to datetime in specified format\n",
    "pd.to_datetime(['20200101', '20200102'], format='%Y%m%d')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "('Unknown string format:', 'not a date')",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/pandas/core/arrays/datetimes.py\u001b[0m in \u001b[0;36mobjects_to_datetime64ns\u001b[0;34m(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object)\u001b[0m\n\u001b[1;32m   1860\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1861\u001b[0;31m             \u001b[0mvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtz_parsed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mconversion\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdatetime_to_datetime64\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1862\u001b[0m             \u001b[0;31m# If tzaware, these values represent unix timestamps, so we\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/tslibs/conversion.pyx\u001b[0m in \u001b[0;36mpandas._libs.tslibs.conversion.datetime_to_datetime64\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;31mTypeError\u001b[0m: Unrecognized value type: <class 'str'>",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-224-842850ec7f71>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_datetime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'20200101'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'not a date'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/pandas/core/tools/datetimes.py\u001b[0m in \u001b[0;36mto_datetime\u001b[0;34m(arg, errors, dayfirst, yearfirst, utc, box, format, exact, unit, infer_datetime_format, origin, cache)\u001b[0m\n\u001b[1;32m    607\u001b[0m             \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_convert_and_box_cache\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcache_array\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbox\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    608\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 609\u001b[0;31m             \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mconvert_listlike\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbox\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mformat\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    610\u001b[0m     \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    611\u001b[0m         \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mconvert_listlike\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbox\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mformat\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/pandas/core/tools/datetimes.py\u001b[0m in \u001b[0;36m_convert_listlike_datetimes\u001b[0;34m(arg, box, format, name, tz, unit, errors, infer_datetime_format, dayfirst, yearfirst, exact)\u001b[0m\n\u001b[1;32m    300\u001b[0m             \u001b[0marg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdayfirst\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdayfirst\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0myearfirst\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0myearfirst\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    301\u001b[0m             \u001b[0mutc\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mutc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0merrors\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrequire_iso8601\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrequire_iso8601\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 302\u001b[0;31m             allow_object=True)\n\u001b[0m\u001b[1;32m    303\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    304\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mtz_parsed\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/pandas/core/arrays/datetimes.py\u001b[0m in \u001b[0;36mobjects_to_datetime64ns\u001b[0;34m(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object)\u001b[0m\n\u001b[1;32m   1864\u001b[0m             \u001b[0;32mreturn\u001b[0m \u001b[0mvalues\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mview\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'i8'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtz_parsed\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1865\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mValueError\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1866\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1867\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1868\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mtz_parsed\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/pandas/core/arrays/datetimes.py\u001b[0m in \u001b[0;36mobjects_to_datetime64ns\u001b[0;34m(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object)\u001b[0m\n\u001b[1;32m   1855\u001b[0m             \u001b[0mdayfirst\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdayfirst\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1856\u001b[0m             \u001b[0myearfirst\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0myearfirst\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1857\u001b[0;31m             \u001b[0mrequire_iso8601\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrequire_iso8601\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1858\u001b[0m         )\n\u001b[1;32m   1859\u001b[0m     \u001b[0;32mexcept\u001b[0m \u001b[0mValueError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/tslib.pyx\u001b[0m in \u001b[0;36mpandas._libs.tslib.array_to_datetime\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/tslib.pyx\u001b[0m in \u001b[0;36mpandas._libs.tslib.array_to_datetime\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/tslib.pyx\u001b[0m in \u001b[0;36mpandas._libs.tslib.array_to_datetime_object\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/tslib.pyx\u001b[0m in \u001b[0;36mpandas._libs.tslib.array_to_datetime_object\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32mpandas/_libs/tslibs/parsing.pyx\u001b[0m in \u001b[0;36mpandas._libs.tslibs.parsing.parse_datetime_string\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/dateutil/parser/_parser.py\u001b[0m in \u001b[0;36mparse\u001b[0;34m(timestr, parserinfo, **kwargs)\u001b[0m\n\u001b[1;32m   1356\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mparser\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mparserinfo\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimestr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1357\u001b[0m     \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1358\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mDEFAULTPARSER\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimestr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1359\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1360\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/dateutil/parser/_parser.py\u001b[0m in \u001b[0;36mparse\u001b[0;34m(self, timestr, default, ignoretz, tzinfos, **kwargs)\u001b[0m\n\u001b[1;32m    647\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    648\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mres\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 649\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Unknown string format:\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimestr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    650\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    651\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mres\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: ('Unknown string format:', 'not a date')"
     ]
    }
   ],
   "source": [
    "# Value Error\n",
    "pd.to_datetime(['20200101', 'not a date'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2020-01-01', 'NaT'], dtype='datetime64[ns]', freq=None)"
      ]
     },
     "execution_count": 225,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Handle value error\n",
    "pd.to_datetime(['20200101', 'not a date'], errors='coerce')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "position": {
    "height": "368px",
    "left": "929px",
    "right": "20px",
    "top": "120px",
    "width": "350px"
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
